package com.wobangkj.common.api.crud;

import com.wobangkj.common.model.crud.Share;
import com.wobangkj.common.service.ShareService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/share")
public class ShareController {
    @Autowired
    private ShareService ShareService;

    @PostMapping(value = "/create")
    public Object create(@RequestBody Share data) {
        // 创建时间
        data.setCreatetime(Timestamp.valueOf(LocalDateTime.now()));
        return ShareService.create(data);
    }

    @PutMapping(value = "/update")
    public Object update(@RequestBody Share share) {

        return ShareService.update(share);
    }

    @DeleteMapping(value = "/delete/{id}")
    public Object delete(@PathVariable(value = "id") Long id) {
        return ShareService.delete(id);
    }

    @GetMapping("/id")
    public Object id(Long id) {

        return ShareService.id(id);
    }


    @GetMapping("/search")
    public Object search(@RequestParam(required = false) Map<String, Object> params, Share share) {
        return ShareService.search(params, share);
    }

    //模糊查询

    @GetMapping("/findByNameLike/{share_title}")
    public List<Share> findByNameLike(@PathVariable(value = "share_title") String share_title){
        // 一定要加 "%"+参数名+"%"
        return ShareService.findByNameLike(share_title);
    }

    @GetMapping("/selectAllShareView")
    public List<Share> selectAllSHareView(){
        return ShareService.selectAllShareView();
    }

    @GetMapping("/list")
    public List<Map> list(){
        return ShareService.list();
    }
    @GetMapping("/listByClass")
    public List<Map> list(Integer share_class){
        return ShareService.list(share_class);
    }
    @GetMapping("/listByScreen")
    public List<Map> list(@RequestParam("share_company")String share_company,@RequestParam("college")Integer college,@RequestParam("major")Integer major,@RequestParam("share_job")String share_job){
        return ShareService.list(share_company,college,major,share_job);
    }

    @PostMapping(value = "/updateForward")
    public Object updateShareForward(Long id) {
        return ShareService.updateShareForward(id);
    }

    @PostMapping(value = "/updateUrl")
    public Object updateUrl(String url,String id) {
        return ShareService.updateUrl(url,id);
    }


}
